using System.Net.Http;
using UnityEngine;
using ZFramework.Runtime;
using ZFramework.Runtime.Download;
using GameWorldOwner = ZFramework.Runtime.Fsm<ZFramework.Runtime.IGameWorldManager>;
namespace ZGame
{
    public class GameWorldLogin : GameWorldBase
    {
        public override void OnEnter(GameWorldOwner gameWorldOwner)
        {
            base.OnEnter(gameWorldOwner);
            Log.Error("开始  GameWorldTest");
            //GameEntry.uiMgr.OpenUI("Assets/Res/FGUI/UIAllianceMain.prefab", "Normal", true, null);
            //GameEntry.uiMgr.OpenUI<UIFormLogicLogin>( "Normal", true, null);
            int downloadId = GameEntry.downloadManager.AddDownload($"{Application.persistentDataPath}/xxx.txt", "http://127.0.0.1:9000/xxx/mytestjson.txt");
            GameEntry.eventMgr.Subscribe(DownloadSuccessEventArgs.EventID, OnLoadSuccess);
            GameEntry.eventMgr.Subscribe(DownloadFailureEventArgs.EventID, OnLoadFailure);
        }

        private void OnLoadSuccess(object sender, GameEventArgs e)
        {
            var args = e as DownloadSuccessEventArgs;
            if (args == null)
                return;
            Log.Error("下载成功");
        }
        
        private void OnLoadFailure(object sender, GameEventArgs e)
        {
            var args = e as DownloadFailureEventArgs;
            if (args == null)
                return;
            Log.Error("下载失败 {0}", args.ErrorMessage);
        }
    }
}